package com.jeesite.modules.video.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.modules.file.entity.FileUpload;
import com.jeesite.modules.file.service.FileUploadService;
import com.jeesite.modules.file.utils.FileUploadUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.video.entity.DcSupVideo;
import com.jeesite.modules.video.service.DcSupVideoService;

import java.util.List;

/**
 * 微课视频Controller
 * @author xhc
 * @version 2022-10-12
 */
@Controller
@RequestMapping(value = "${adminPath}/video/dcSupVideo")
public class DcSupVideoController extends BaseController {

	@Autowired
	private DcSupVideoService dcSupVideoService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupVideo get(String id, boolean isNewRecord) {
		return dcSupVideoService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("video:dcSupVideo:view")
	@RequestMapping(value = {"list", ""})
	public String list(DcSupVideo dcSupVideo, Model model) {
		model.addAttribute("dcSupVideo", dcSupVideo);
		return "modules/video/dcSupVideoList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("video:dcSupVideo:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupVideo> listData(DcSupVideo dcSupVideo, HttpServletRequest request, HttpServletResponse response) {
		dcSupVideo.setPage(new Page<>(request, response));
		Page<DcSupVideo> page = dcSupVideoService.findPage(dcSupVideo);
		page.getList().forEach(x->{

			x.setFileUrl("/whdc/a/file/download/"+x.getFileId());}
		);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("video:dcSupVideo:view")
	@RequestMapping(value = "form")
	public String form(DcSupVideo dcSupVideo, Model model) {
		model.addAttribute("dcSupVideo", dcSupVideo);
		return "modules/video/dcSupVideoForm";
	}

	/**
	 * 保存数据
	 */
	@RequiresPermissions("video:dcSupVideo:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated DcSupVideo dcSupVideo) {
		dcSupVideoService.save(dcSupVideo);
		return renderResult(Global.TRUE, text("保存微课视频成功！"));
	}
	
	/**
	 * 停用数据
	 */
	@RequiresPermissions("video:dcSupVideo:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(DcSupVideo dcSupVideo) {
		dcSupVideo.setStatus(DcSupVideo.STATUS_DISABLE);
		dcSupVideoService.updateStatus(dcSupVideo);
		return renderResult(Global.TRUE, text("停用微课视频成功"));
	}
	
	/**
	 * 启用数据
	 */
	@RequiresPermissions("video:dcSupVideo:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(DcSupVideo dcSupVideo) {
		dcSupVideo.setStatus(DcSupVideo.STATUS_NORMAL);
		dcSupVideoService.updateStatus(dcSupVideo);
		return renderResult(Global.TRUE, text("启用微课视频成功"));
	}
	
	/**
	 * 删除数据
	 */
	@RequiresPermissions("video:dcSupVideo:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(DcSupVideo dcSupVideo) {
		dcSupVideoService.delete(dcSupVideo);
		return renderResult(Global.TRUE, text("删除微课视频成功！"));
	}
	
}